<?php
namespace app\admin\model;

use think\Model;
class Template extends Model
{
    public function deleteTemp($id)
    {
        if(empty($id)){
            return false;
        }
        $where = [
            'id' => $id
        ];
        $result = $this->where($where)->delete();
        return $result;
    }

    public function addTemp($typeId, $tempName){
        $add = [
            'type_id'=>$typeId,
            'temp_name'=>$tempName,
            'create_time'=>time(),
        ];
        $result = $this->add($add);
        return $result;
    }

    public function getList(){
        $field = [
            'id',
            'type_id',
            'temp_name',
            'create_time',
        ];
        $result = $this->field($field)->select();
        $typeModel=D('Type');
        foreach($result as $key=>$value){
            $result[$key]['type_name']=$typeModel->getIdName($value['type_id']);
            $result[$key]['create_time']=date('Y/m/d', $value['create_time']);
        }
        return $result;
    }
}
